/**
 * ZipString.java created by zhangzhidong 
 * at 上午11:05:28 2015年9月25日
 */
package algorithm;

/**
 * @author Alex
 *
 */
public class ZipString {

	
	
	    public static String zipString(String iniString) {
	        // write code here
	    	 String result = "";
	         int i = 0;
	         int j = 0;
	         for( i=0;i<iniString.length();){
	             j=i+1;
	             while(j<iniString.length()){
	                 if(iniString.charAt(i)==iniString.charAt(j)){
	                   
	                     j++;
	                 }else{
	                    break;
	                 }
	             }
	            
	             result+=String.valueOf(iniString.charAt(i))+String.valueOf(j-i);
	             i=j;
	             
	         }
	       	if(result.length()>iniString.length()) return iniString;
	         else
	         return result;
	    }
	
	
	/**
	 * 上午11:05:28 2015年9月25日
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws InterruptedException {
		T t = new T();
		t.start();
		
//		Thread.sleep(2000);
//		t.isRunning = false;
		t.join();
		System.out.println("main exit");
		// TODO Auto-generated method stub
//	System.out.println(zipString("fffffffffffffffffasdfs"));
//		main(args);
	}
	static class T extends Thread{
		public boolean isRunning = true;
		int i = 0;
		public void run(){
//			while(isRunning){
//				try {
//					Thread.sleep(2000);
//				} catch (InterruptedException e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//				System.out.println("running...."+i);
//				
//				i++;
//			}
			
			for(int i = 0;i<5;i++){
				System.out.print(i);
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			
			
			
		}
		
	}
	
	
	

}
